package ChaiPiao;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class PlayTypeValuesEnumeration extends AbstractListEnumerable<String, GameSelection> {
    private String gameId;
    private String playType;
    private Set<String> typeValues;

    public PlayTypeValuesEnumeration(String gameId, String playType) {
        this.gameId = gameId;
        this.playType = playType;
        typeValues = new HashSet<>();
    }

    public void addTypeValue(String value) {
        if (!this.typeValues.contains(value)) {
            super.addSource(value);
        }
        this.typeValues.add(value);
    }

    public int valueCount() {
        return this.typeValues.size();
    }

    public String getGameId() {
        return gameId;
    }

    public String getPlayType() {
        return playType;
    }

    /***************************************
     * get set equals
     ***************************/


    @Override
    public String toString() {
        String split = ",";
        StringBuffer stringBuffer = new StringBuffer();
        List<String> values = new ArrayList<>(typeValues);
        for (int i = 0; i < values.size(); i++) {
            if (i == values.size() - 1)
                split = "";
            stringBuffer.append(values.get(i)).append(split);
        }

        return gameId + ":" + playType + ":" + stringBuffer.toString();
    }

    /**
     * 赛事id和玩法一致即为相同
     *
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PlayTypeValuesEnumeration that = (PlayTypeValuesEnumeration) o;

        if (gameId != null ? !gameId.equals(that.gameId) : that.gameId != null) return false;
        return playType != null ? playType.equals(that.playType) : that.playType == null;
    }

    @Override
    public int hashCode() {
        int result = gameId != null ? gameId.hashCode() : 0;
        result = 31 * result + (playType != null ? playType.hashCode() : 0);
        return result;
    }


    /***************************************
     * override
     ************************************/
    @Override
    protected GameSelection source2result(String source) {
        return new GameSelection(this.getGameId(), this.getPlayType(), source);
    }
}
